<template>
  <div>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="账户" prop="username">
        <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="userPassword">
        <el-input type="password" v-model="ruleForm.userPassword" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button @click="register()">注册</el-button>
        <el-button @click="remind">密码提示</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data() {
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入账户'));
        } else {
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        }else {
          callback();
        }
      };
      return {
        ruleForm: {
          username: '',
          userPassword: '',
        },
        rules: {
          username: [
            { validator: validatePass, trigger: 'blur' }
          ],
          userPassword: [
            { validator: validatePass2, trigger: 'blur' }
          ],

        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$http.post("user/login",this.ruleForm).then(result=>{
              console.log(result);
              this.$notify({
                title: result.data.success,
                message: result.data.message,
                type: 'success'
              });
            });

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      remind() {
            this.$http.post("user/remind",this.ruleForm).then(result=>{
              console.log(result);
              this.$notify({
                title: result.data.success,
                message: result.data.message,
                type: 'success'
              });
            });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      register(){
        this.$router.push('/Register')
      }
    }
  }
</script>
